$( document ).ready(function() {
	// Handler for .ready() called.
	if($("#patient-registration-form").length > 0) {
		$("#patient-registration-form").validate({
			rules: {
				"guiPatient.name": {
					required: true
				},
				"guiPatient.dob": {
					required: true
				},
				"guiPatient.contact.telNo": {
					required: true
				},
				"guiPatient.contact.address": {
					required: true
				}
			},
			
			messages: {
				"guiPatient.name": {
					required: "Please specify the patient name"
				},
				"guiPatient.dob": {
					required: "Please specify the date of birth"
				},
				"guiPatient.contact.telNo": {
					required: "Please specify the patient telephone number"
				},
				"guiPatient.contact.address": {
					required: "Please specify the patient address"
				}
			},
			
			submitHandler: function(form) { 
				form.submit();  
			}
			
		});
	}

	//user contact format
	if ($(".user-contact").length > 0) {
		$(".user-contact").mask("(999) 999-9999");
	}

	// init calendar
	if ($("#dob-picker").length > 0) {
		$("#dob-picker").datepicker();
	}
	
	// init delete button
	if ($("#btn-delete").length > 0) {
		$("#btn-delete").on('click', function(e){
			e.preventDefault();
			$.Dialog({
				shadow: true,
				overlay: true,
				icon: '<span class="icon-remove"></span>',
				title: 'Delete Confirmation',
				width: 400,
				padding: 10,
				onShow: function(_dialog){
 					var content = _dialog.children('.content');
 					content.html('<div class="subheader-secondary" style="width:400px">Do you want to delete patient\'s all (prescription, appointment ...etc) information?</div><br/><div><a id="btn-delete" href="' + $("#btn-delete").attr('href') + '" class="button">Delete</a></div>');
				}
			});
		});
	}
	
	//error message notifier
	if ($("ul.errorMessage li span").length > 0) {
		$("ul.errorMessage li span").each(function(){
			$.Notify({
					 	  caption: "Try Again!",
						  content: $(this).text(),
						  timeout: 5000,
						  style: {background: '#1ba1e2', color: 'white'}
					 });
		});
	}
	
	if($("#btn-printpatients").length > 0) {
		$("#btn-printpatients").click(function() {  
			window.print();  
			return false;  
		});
	}  
	
});
